<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\ChOperationLog;
use App\CustHub\Annotation\ChPermission;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\KeywordTagRequest;
use App\CustHub\Service\ChKeywordTagSchemeService;
use App\CustHub\Service\ChOpSchemeService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;


#[Controller(prefix: 'ch/keyword/scheme'),ApiAuth,VerifySignature]
class KeywordTagSchemeController extends BaseController
{

    #[Inject]
    protected ChKeywordTagSchemeService $service;

    /**
     * 列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('list'),ChPermission('ch:keyword:scheme:list')]
    public function list(): ResponseInterface
    {
        return $this->success($this->service->list($this->request->all()));
    }

    /**
     * 新增
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('save'),ChPermission('ch:keyword:scheme:save'),ChOperationLog]
    public function save(KeywordTagRequest $request): ResponseInterface
    {
        return $this->success(['id'=>$this->service->save($request->all())]);
    }

    /**
     * 编辑
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('update'),ChPermission('ch:keyword:scheme:update'),ChOperationLog]
    public function update(KeywordTagRequest $request): ResponseInterface
    {
        return $this->service->update($request->input('id'),$request->all()) ? $this->success() : $this->error();
    }

    /**
     * 删除
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('delete'),ChPermission('ch:keyword:scheme:delete'),ChOperationLog]
    public function delete(KeywordTagRequest $request): ResponseInterface
    {
        return $this->service->deleteScheme($request->input('id')) ? $this->success() : $this->error();
    }
}